package com.zh.gulimall.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @author xiezhaohui
 * @date 2021/11/9
 */
@Configuration
public class GuliCrosConfiguration {

    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration crosConfiguration = new CorsConfiguration();
        crosConfiguration.addAllowedHeader("*");
        crosConfiguration.addAllowedMethod("*");
        crosConfiguration.addAllowedOrigin("*");
        crosConfiguration.setAllowCredentials(true);
        source.registerCorsConfiguration("/**",crosConfiguration);
        return new CorsWebFilter(source);
    }
}
